<template>
  <div class="container" @mouseover="setIsHoverTrue" @mouseout="setIsHoverFalse">
    <el-card class="paperCard" shadow="hover">
      <div slot="header" class="header">
        <span>{{tp.tp_name}}</span>
      </div>
      <div class="body">
        <div class="description">{{tp.tp_description}}</div>
        <div class="create_date">{{"创建时间："+createDate}}</div>
        <el-button class="Card_button"  type="text" @click="toWhere">查看试卷</el-button>
        <el-button class="Card_button"  type="text" @click="deletetp">删除</el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
import moment from 'moment';
import axiosinstance from "@/util/http";

export default {
  name: "paperItem",
  computed:{
    createDate:function (){
      if(this.isHover)return moment(this.tp.createdAt).format('YYYY-MM-DD HH:mm');
      else  return moment(this.tp.createdAt).format('MM-DD HH:mm');
    },
  },
  props: {
   
    tp:{
      type:Object,
      default: function () {
          return {
            username:null
          };
      }
    }
  },
  data() {
    return{
      tpList:[],
      isHover:false,
    }
  },
  methods:{

      toWhere() {
      this.$emit("aSignal", this.tp.tp_id, this.tp.tp_name);
      this.$router.push({
        path: "PaperDetail",
        query: {
          tp_id: this.tp.tp_id,
        },
      });
      console.log(this.$route.query);
    },

    async refreshtpList(){
      await axiosinstance.get('/paper/testpaperlist',{
        params:{
          page:this.page,
          pageSize:this.pageSize,
          username:this.$store.getters.getuser.username
        }
      }).then(res =>{
        this.tpList = res.data?.data;
        console.log(res.data)
      } )
    },
    setIsHoverTrue(){
      this.isHover = true;
    },
    setIsHoverFalse(){
      this.isHover = false;
    },
     async deletetp() {
      this.user = this.$store.getters.getuser;
      console.log("efa", this.user);
      this.tp_id=this.tp.tp_id;
      console.log("afafqa", this.tp_id);

      let res = await axiosinstance({
        url: '/paper/deletetestpaper',
        method: 'post',
        data:{
          username: this.user.username,
          tp_id: this.tp.tp_id,
        }
      });
      if(res){
        this.$message({
          showClose: true,
          message: '删除成功',
          type: 'success'
        });
        // this.$router.go(0);
        this.$emit("deletetp",this.tp_id);
       }else{
        this.$message({
          showClose: true,
          message: '删除失败',
          type: 'err'
        });
      }
    

    },
  }

}
</script>

<style scoped lang="less">
  .container{
    margin:0;
    height:inherit;
    width:100%;
    padding:0;
    .paperCard{
      height:inherit;
      border:2px solid rgb(255, 255, 255);
      border-radius:35px;
      //transition: all 250ms cubic-bezier(.02, .01, .47, 1);
      transition-delay: 0.04s;
      transition-duration:0.7s;
      &:hover{
        transform: translate(0,-5px);
        border-radius:15px;
        transition-delay: 0.13s;
        transition-duration:0.7s;
      }

      .header{

      }
      .body{
        .description{
          overflow:hidden;
          display:block;
          height:100%;
          width:100%;

        }
       
      }
    }

  }


</style>